package com.wn.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.wn.pojo.Subject;
import com.wn.service.ISubjectService;
import com.wn.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author yellow docker
 * @since 2023-06-20
 */
@RestController
@RequestMapping("/subject")
public class SubjectController  extends BaseController{

    @Autowired
    private ISubjectService subjectService;

    @GetMapping("{parentId}")
    public Result findSubjectByParentId(@PathVariable("parentId")String parentId){
        List<Subject> subjects = subjectService.findSubjectByParentId(parentId);
        return toDataResult(subjects);
    }

    @GetMapping("/all")
    public Result findSubjects(){

        LambdaQueryWrapper<Subject> lambdaQuery = Wrappers.lambdaQuery(Subject.class);
        //条件 parentId != 0
        lambdaQuery.ne(Subject::getParentId,"0");
        List<Subject> subjects = subjectService.list(lambdaQuery);

        return toDataResult(subjects);
    }

}
